
<?php

defined('BASEPATH') or die('forbidden');
//登陆异常跟踪
class fenxiReportgraph_Controller Extends Controller {
		
	private $eventTypeList;	//事件列表
	private $eventGraphList;	//传给显示界面的变量
	private $channelList;	//渠道列表
	private $platformList;	//平台列表
	private $osverList;		//操作系统列表
	private $networkList;	//网络类型
	private $deviceList;	//设备类型
	private $gameverList;	//游戏版本类型
	
	private $recdb;	//用户登陆日志
	
    function _init() {
        check_level(50, segment(0), segment(1));
        require (CONFIGPATH . 'db.php');
        
        //$this->recdb->select_db("crashreport");
        //var_dump($config['buglist']);
		$this->recdb = new Database($config['buglist']);
		
    	$this->getEventType();
    	$this->getChannelType();
        $this->getPlatformList();
        $this->getOsverList();
        $this->getNetworkList(); 
        $this->getDeviceList();
        $this->getGameverList();
    }

    function index() {
    	
    	$reportGraph = array();	//传给图表的数据
    	
    	$where = ' ';
    	$channel = 'all';
    	$platform = 'all';    	
    	$osver = 'all';
    	$network = 'all';
    	$device = 'all';
    	$gamever = 'all';
    	if (is_submit()) 
    	{
    		//print_r($_POST);
    		$startTime=$_POST['row']['starttime'];
            $endTime = $_POST['row']['endtime'];  
            $channel = $_POST['row']['channel'];
            $platform = $_POST['row']['platform'];
            $osver = $_POST['row']['osver'];
            $network = $_POST['row']['network'];
            $device = $_POST['row']['device'];
            $gamever = $_POST['row']['gamever'];
            
            if ('all' != $channel) {
            	$where .= " and channel = '$channel' ";
            }
            
    		if ('all' != $platform) {
            	$where .= " and platform = '$platform' ";
            	//echo "platfrom = ".$platform;
            	$platform = $this->platformList[$platform];
            	//print_r($this->platformList);
            	//echo "platfrom = ".$platform;
            }
            
    		if ('all' != $osver) {
            	$where .= " and osVer = '$osver' ";
            }
            
    		if ('all' != $network) {
            	$where .= " and netWorkType = '$network' ";
            	$network = $this->networkList[$network];
            }
            
    		if ('all' != $device) {
            	$where .= " and deviceName = '$device' ";
            }
            
    		if ('all' != $gamever) {
            	$where .= " and gameVer = '$gamever' ";
            }
            
    	}else 
    	{
    		$startTime = date("Y-m-d");
    		$endTime = date("Y-m-d",strtotime("+1 day"));
    	}
    	
    	$sql = "select * from analysereport where inserttime between '$startTime' and '$endTime' ".$where." order by insertTime asc ";
    	//echo "sql = $sql";
    	$this->recdb->query($sql);
		//$id = 0;
		//print_r($this->eventTypeList);
		while ($n = $this->recdb->get_array('default'))
		{	
			//print_r($n);		
			//foreach ($n as $key=>$value)
			{				
				//去掉几个字段
				unset($n['id']);	
				
				//有几个数据需要转换下
				$n['platform']=$this->platformList[$n['platform']];
				$n['netWorkType']=$this->networkList[$n['netWorkType']];		
				
				$reportGraph[$n['insertTime']]['loginstart'] += $n['loginstart'];
				$reportGraph[$n['insertTime']]['checkupdate'] += $n['checkupdate'];
				$reportGraph[$n['insertTime']]['checkxml'] += $n['checkxml'];
				$reportGraph[$n['insertTime']]['getxml'] += $n['getxml'];
				$reportGraph[$n['insertTime']]['getxmlreturn'] += $n['getxmlreturn'];
				$reportGraph[$n['insertTime']]['sdkstart'] += $n['sdkstart'];
				$reportGraph[$n['insertTime']]['conloginserver'] += $n['conloginserver'];
				$reportGraph[$n['insertTime']]['conloginserverback'] += $n['conloginserverback'];
				$reportGraph[$n['insertTime']]['threelogin'] += $n['threelogin'];
				$reportGraph[$n['insertTime']]['loginsuccess'] += $n['loginsuccess'];
				$reportGraph[$n['insertTime']]['verifytokenover'] += $n['verifytokenover'];
				$reportGraph[$n['insertTime']]['verifytoken'] += $n['verifytoken'];
				$reportGraph[$n['insertTime']]['verifyaccount'] += $n['verifyaccount'];
				$reportGraph[$n['insertTime']]['verifyaccountover'] += $n['verifyaccountover'];
				$reportGraph[$n['insertTime']]['selectarea'] += $n['selectarea'];
				$reportGraph[$n['insertTime']]['selectareaback'] += $n['selectareaback'];
				$reportGraph[$n['insertTime']]['congateserver'] += $n['congateserver'];
				$reportGraph[$n['insertTime']]['congateserverback'] += $n['congateserverback'];
				$reportGraph[$n['insertTime']]['selectrole'] += $n['selectrole'];
				$reportGraph[$n['insertTime']]['startgame'] += $n['startgame'];			}
		}
		//print_r($reportGraph);
		$this->view->assign("channel",$channel);
		$this->view->assign('platform',$platform);
		$this->view->assign('osver',$osver);
		$this->view->assign('network',$network);
		$this->view->assign('device',$device);
		$this->view->assign('gamever',$gamever);
		$this->view->assign('startTime',$startTime);
		$this->view->assign('endTime',$endTime);
		
    	$this->view->assign("reportGraph",$reportGraph);
    	$this->view->assign('eventGraphList',$this->eventGraphList);
    	$this->view->assign('channelList',$this->channelList);
    	$this->view->assign('platformList',$this->platformList);
    	$this->view->assign('osverList',$this->osverList);
    	$this->view->assign('networkList',$this->networkList);
    	$this->view->assign('deviceList',$this->deviceList);
    	$this->view->assign('gameverList',$this->gameverList);
        $this->view->display("message/fenxiReportgraph/index");
    }     

    function  getEventType()
    {
    	$sql = "SELECT *  FROM eventtype ";
        $this->recdb->query($sql);
    	while ($n = $this->recdb->get_array('default')) 
    	{
   			$this->eventTypeList[$n['columName']]['eventValue'] = $n['eventValue'];
   			$this->eventTypeList[$n['columName']]['eventStep'] = $n['eventStep'];
   			$this->eventTypeList[$n['columName']]['eventID'] = $n['eventID'];
   			
   			$this->eventGraphList[$n['eventStep']] = $n['eventValue'];
        } 
    	//print_r($this->eventTypeList);
    	return true;
    }
    
    function getChannelType()
    {
    	 $sql = "SELECT *  FROM channeltype ";
        $this->recdb->query($sql);
    	while ($n = $this->recdb->get_array('default')) 
    	{
   			$this->channelList[$n['channel']] = $n['channel'];
        } 
    	//print_r($this->channelList);
    	return true;
    }
    
	function getPlatformList()
    {
    	 $sql = "SELECT *  FROM platformtype ";
        $this->recdb->query($sql);
    	while ($n = $this->recdb->get_array('default')) 
    	{
   			$this->platformList[$n['platformid']] = $n['platformname'];
        } 
    	//print_r($this->platformList);
    	return true;
    }
    
	function getOsverList()
    {
    	 $sql = "SELECT *  FROM osvertype ";
		$this->recdb->query($sql);
    	while ($n = $this->recdb->get_full_array('default')) 
    	{
    		//print_r($n);
   			$this->osverList[$n['osver']] = $n['osver'];
        } 
    	//print_r($this->osverList);
    	return true;
    }
    
	function getNetworkList()
    {
    	 $sql = "SELECT *  FROM networktype ";
        $this->recdb->query($sql);
    	while ($n = $this->recdb->get_array('default')) 
    	{
   			$this->networkList[$n['networkid']] = $n['networkname'];
        } 
    	//print_r($this->networkList);
    	return true;
    }
    
	function getDeviceList()
    {
    	 $sql = "SELECT *  FROM devicetype ";
        $this->recdb->query($sql);
    	while ($n = $this->recdb->get_array('default')) 
    	{
   			$this->deviceList[$n['devicename']] = $n['devicename'];
        } 
    	//print_r($this->deviceList);
    	return true;
    }
    
	function getGameverList()
    {
    	 $sql = "SELECT *  FROM gamevertype ";
        $this->recdb->query($sql);
    	while ($n = $this->recdb->get_array('default')) 
    	{
   			$this->gameverList[$n['gamever']] = $n['gamever'];
        } 
    	//print_r($this->gameverList);
    	return true;
    }
}